package com.zqx.spmab.commons;

import com.zqx.spmab.utils.JsonUtil;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

/**
 * Created by Zqx on 2018/4/24.
 */
public class JsonResultBean implements Serializable{
    private static final long serialVersionUID = -6523232100667114952L;
    public static final boolean SUCCESS = true;
    public static final boolean FAULT = false;
    private boolean success;
    private String msg;
    private String exceptionDetailMsg;
    private Object obj;

    public JsonResultBean() {
        this.success = true;
    }

    public JsonResultBean(String message) {
        this.success = true;
        this.msg = message;
    }

    public JsonResultBean(Object object) {
        this.success = true;
        this.obj = object;
    }

    public JsonResultBean(boolean suc) {
        this.success = suc;
    }

    public JsonResultBean(boolean suc, String message) {
        this.success = suc;
        this.msg = message;
    }

    public JsonResultBean(Throwable exceptionMessage) {
        exceptionMessage.printStackTrace(new PrintWriter(new StringWriter()));
        this.success = false;
        this.msg = exceptionMessage.getMessage();
    }

    public JsonResultBean(Throwable exceptionMessage, boolean detailMsg) {
        exceptionMessage.printStackTrace(new PrintWriter(new StringWriter()));
        this.success = false;
        this.msg = exceptionMessage.getMessage();
        if(detailMsg) {
            this.exceptionDetailMsg = exceptionMessage.toString();
        }

    }

    public boolean isSuccess() {
        return this.success;
    }

    public String getMsg() {
        return this.msg;
    }

    public Object getObj() {
        return this.obj;
    }

    public String getExceptionDetailMsg() {
        return this.exceptionDetailMsg;
    }

    public String toString() {
        return JsonUtil.object2Json(this);
    }
}
